package com.rem.hutool.my12Excel;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.poi.excel.ExcelUtil;

import java.util.regex.Pattern;

/**
 * @author Rem
 * @date 2021-10-28
 */

public class ExcelImport {

    static Pattern pattern = Pattern.compile("[\\d]*");


    public static void main(String[] args) {
        ExcelUtil.readBySax("d:/xxx4.csv", -1, (sheetIndex, rowIndex, rowList) -> {
            if (rowIndex != 0 && rowIndex <= 100000) {
                try {
                    if (CollectionUtil.hasNull(rowList)) {
                        throw new RuntimeException("第" + (rowIndex + 1) + "行必填项为空");
                    }

                    String s2 = rowList.get(2).toString();
                    int numb = NumberUtil.parseNumber(s2).intValue();
                    if (numb < 0) {
                        throw new RuntimeException("第" + (rowIndex + 1) + "行建议值有误");
                    }
                    if (numb != NumberUtil.parseDouble(s2)) {
                        throw new RuntimeException("第" + (rowIndex + 1) + "行建议值有误");
                    }

                    OplPo oplPo = new OplPo(NumberUtil.parseInt(rowList.get(0).toString()), NumberUtil.parseLong(rowList.get(1).toString()), numb);
                    Console.log("[{}] [{}] {}", sheetIndex, rowIndex, oplPo);
                } catch (NumberFormatException e) {
                    throw new RuntimeException("第" + (rowIndex + 1) + "转换异常");
                } catch (RuntimeException e) {
                    e.printStackTrace();
                    throw new RuntimeException(e.getMessage());
                }
            }
        });
    }

}
